#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int a[N];
int L[N], R[N];
ll sum[N];
ll d[N], s[N];
ll ans[N];
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) sum[i] = sum[i - 1] + a[i];
  stack<int> st;
  rep(i, 0, n) {
    while (st.size() && sum[st.top()] < sum[i]) {
      R[st.top()] = i - 1;
      st.pop();
    }
    L[i] = st.empty() ? 0 : st.top() + 1;
    st.push(i);
  }
  while (st.size()) {
    R[st.top()] = n;
    st.pop();
  }
  rep(i, 1, n + 1) d[i] = 0;
  rep(i, 0, n) {
    int mn = i + 1 - L[i], mx = R[i] + 1 - i, len = mn + mx - 1;
    d[1] += sum[i], d[mn + 1] -= sum[i];
    d[mx + 1] -= sum[i], d[len + 2] += sum[i];
  }
  rep(i, 1, n + 1) d[i] += d[i - 1];
  rep(i, 1, n + 1) d[i] += d[i - 1];
  rep(i, 1, n + 1) ans[i] = d[i];

  while (st.size()) st.pop();
  rep(i, 0, n) {
    while (st.size() && sum[st.top()] > sum[i]) {
      R[st.top()] = i - 1;
      st.pop();
    }
    L[i] = st.empty() ? 0 : st.top() + 1;
    st.push(i);
  }
  while (st.size()) {
    R[st.top()] = n;
    st.pop();
  }
  rep(i, 1, n + 1) d[i] = 0;
  rep(i, 0, n) {
    int mn = i + 1 - L[i], mx = R[i] + 1 - i, len = mn + mx - 1;
    d[1] -= sum[i], d[mn + 1] += sum[i];
    d[mx + 1] += sum[i], d[len + 2] -= sum[i];
  }
  rep(i, 1, n + 1) d[i] += d[i - 1];
  rep(i, 1, n + 1) d[i] += d[i - 1];
  rep(i, 1, n + 1) ans[i] += d[i];
  ll res = 0;
  rep(k, 1, n) res ^= ans[k + 1] % (1ll * k * k);
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}